package org.jypj.dev.controller;

import org.jypj.dev.dao.ShoesDao;
import org.jypj.dev.model.Shoes;
import org.jypj.dev.util.ShoesUtil;
import org.jypj.dev.vo.BaseInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by ChenYu on 2017-07-03.
 */
@Controller
@RequestMapping(value = "app")
public class WebAppController extends BaseController {

    @Resource
    private ShoesDao shoesDao;

    /**
     * 首页
     *
     * @return
     */
    @RequestMapping(value = "index")
    public String toIndex() {

        return "webApp/index";
    }

    /**
     * 精品鞋款
     *
     * @return
     */
    @RequestMapping(value = "shoes")
    public String toShoes(Shoes shoes, HttpServletRequest request, String type) {
        shoes.setStatus("1");
        shoes.setShoeBelow("皮底");
        List<Shoes> shoes1 = shoesDao.selectAllByShoes(shoes);
        if ("1".equals(type)) {
            BaseInfo currentBaseInfo = getCurrentBaseInfo();
            currentBaseInfo.setSelectShoeColor(shoes.getColor());
            currentBaseInfo.setSelectShoeBelow(shoes.getShoeBelow());
            currentBaseInfo.setSelectShoeMaterial(shoes.getMaterial());
            currentBaseInfo.setSelectShoeStyle(shoes.getStyle());
        }
        request.setAttribute("shoesList", shoes1);
        return "webApp/jpxk";
    }

    /**
     * 精品鞋款详情
     *
     * @return
     */
    @RequestMapping(value = "shoes/{id}")
    public String toShoesInfo(@PathVariable String id, HttpServletRequest request) {
        Shoes shoes = shoesDao.selectShoesById(id);
        request.setAttribute("s", shoes);
        //查询同一款式的颜色
        List<String> strings = shoesDao.selectAllColor(shoes.getStyle(), shoes.getBelongSex());
        request.setAttribute("colors", strings);
        //查询同一款式的鞋底
        List<String> showBelows = shoesDao.selectAllShowsBelows(shoes.getName());
        request.setAttribute("shoeBelows", showBelows);
        //查找颜色相同的鞋子
        List<Shoes> shoes1 = shoesDao.selectAllByShoesLm(ShoesUtil.initSimilar(shoes), id);
        request.setAttribute("ss", shoes1);
        return "webApp/jpxk_xq";
    }


    /**
     * 高级定制
     *
     * @return
     */
    @RequestMapping(value = "best")
    public String toBest() {

        return "webApp/gjdz";
    }

    /**
     * 护理保养
     *
     * @return
     */
    @RequestMapping(value = "care")
    public String toCare() {

        return "webApp/hlby";
    }

    /**
     * 精彩活动
     *
     * @return
     */
    @RequestMapping(value = "active")
    public String toActive() {

        return "webApp/jchd";
    }

    /**
     * media
     *
     * @return
     */
    @RequestMapping(value = "media")
    public String toMedia() {

        return "webApp/media";
    }

    /**
     * 联系我们
     *
     * @return
     */
    @RequestMapping(value = "tel")
    public String toTel() {

        return "webApp/lxwm";
    }

    /**
     * 工作机会
     *
     * @return
     */
    @RequestMapping(value = "chance")
    public String toChance() {

        return "webApp/gzjh";
    }

    @RequestMapping(value = "law")
    public String toLaw() {

        return "webApp/flsm";
    }

    /**
     * 品牌故事
     *
     * @return
     */
    @RequestMapping(value = "story")
    public String toStory() {

        return "webApp/ppgs";
    }

}
